@*
* Copyright 2015 Yahoo Inc. Licensed under the Apache License, Version 2.0
* See accompanying LICENSE file.
*@
@import kafka.manager.utils.LongFormatted
@(cluster:String, consumer: String, topic: String, state: kafka.manager.model.ActorModel.ConsumedTopicState
)(implicit messages: play.api.i18n.Messages, request:RequestHeader)


@implicitFieldConstructor = @{ b4.vertical.fieldConstructor() }
@getTopicCoverage(percentage: Int) = {
    @percentage match {
        case i if i <=  99 => {table-danger}
        case i => {}
    }
}

@ifPartitionNotOwned(owner: Option[String]) = {
    @owner match {
    case None => {table-warning}
    case Some(a) => {}
    }
}

<div class="row">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header"><h4>Topic Summary</h4></div>
            <div class="card-body">
            <table class="table">
                <tbody>
                <tr>
                    <td>Total Lag</td>
                    <td>@state.totalLag.map(_.formattedAsDecimal).getOrElse(" ")</td>
                </tr>
                <tr>
                    <td>% of Partitions assigned to a consumer instance</td>
                    <td class="@getTopicCoverage(state.percentageCovered)">@state.percentageCovered</td>
                </tr>
                </tbody>
            </table>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header"><h4><a href="@routes.Topic.topic(cluster,topic)">@topic</a></h4></div>
            <div class="card-body">
            <table class="table">
                <thead>
                <tr><th>Partition</th><th>LogSize</th><th>Consumer Offset</th><th>Lag</th><th>Consumer Instance Owner</th></tr>
                </thead>
                <tbody>
                @for(tp:Int <- 0 until state.numPartitions) {
                <tr>
                    <td>@tp</td>
                    <td>@state.topicOffsets(tp).map(_.formattedAsDecimal).getOrElse(" ")</td>
                    <td>@state.partitionOffsets.get(tp).map(_.formattedAsDecimal).getOrElse(" ")</td>
                    <td>@state.partitionLag(tp).map(_.formattedAsDecimal).getOrElse(" ")</td>
                    <td class="@ifPartitionNotOwned(state.partitionOwners.get(tp))">@state.partitionOwners.get(tp).getOrElse("None")</td>
                </tr>
                }
                </tbody>
            </table>
            </div>
        </div>
    </div>
</div>
